package com.sun.filesigndemo.common.security.Realm;



import com.sun.filesigndemo.common.entity.User;
import com.sun.filesigndemo.common.security.UserUtils;

import java.io.Serializable;

public class Principal implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private Long id; // 编号
	private String loginName; // 登录名
	private String name; // 姓名
	private boolean mobileLogin; // 是否手机登录
	private User user;

	public Principal(User user, boolean mobileLogin) {
		this.user= user;
		this.id = user.getId();
		this.loginName = user.getPhone();
		this.name = user.getName();
		this.mobileLogin = mobileLogin;
	}
	public Principal(User user) {
		this.user= user;
		this.id = user.getId();
		this.loginName = user.getPhone();
		this.name = user.getName();
	}

	public Long getId() {
		return id;
	}

	public String getLoginName() {
		return loginName;
	}

	public String getName() {
		return name;
	}

	public boolean isMobileLogin() {
		return mobileLogin;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * 获取SESSIONID
	 */
	public String getSessionid() {
		try{
			return (String) UserUtils.getSession().getId();
		}catch (Exception e) {
			return "";
		}
	}
	
	@Override
	public String toString() {
		return id.toString();
	}

}